<template>
    <div>
<table>
    <tr>
        <td>用户名:</td>
        <td><input type="text" v-model="data.name"></td> 
    </tr>
    <tr>
        <td>密码:</td>
        <td><input type="password" v-model="data.pwd"></td> 
    </tr>
    <tr>
        <td></td>
        <td><input type="button" value="登录" @click="login"></td> 
    </tr>
</table>
    </div>
</template>

<script setup lang="ts">
import { ref } from 'vue';
import { useRouter } from 'vue-router';
import axios from 'axios';
import{ useLoginStore } from '@/stores/logindata';
const router = useRouter();
const user = useLoginStore();
const data= ref({
  "id": 0,
  "name": "",
  "pwd": ""
})
const login =()=>{
  if(data.value.name==""||data.value.pwd==""){
    alert("用户名或密码不能为空")
    return;
  }else{
    axios.get("https://localhost:7167/api/Member/Login",{params:data.value}).then(res=>{
        if(res.data.id > 0){
            alert("登录成功");
            user.user.username= data.value.name
            user.user.islogin=true;
            router.push({path:'/LoginShowView'})
        }
        else if(res.data.id == -1){
            alert("用户名不存在");
            return;
        }
        else if(res.data.id == -2){
            alert("密码错误");
            return;
        }
    })
  }
}
</script>

<style scoped>

</style>    